//
//  ZXAvoidCrashReport.m
//  ZXAvoidCrash
//
//  Created by 朱新明 on 2023/3/14.
//

#import "ZXAvoidCrashReport.h"
#import "ZXAvoidCrashManager.h"

@implementation ZXAvoidCrashReport

+ (void)crashReportWithException:(NSException *)exception{
    
    [self crashReportWithException:exception avoidCrashHandleType:AvoidCrashHandleType_unknown];
}

+ (void)crashReportWithException:(NSException *)exception avoidCrashHandleType:(AvoidCrashHandleType)type{
    
    NSString *reason = exception.reason;
    NSArray *callStackSymbols = exception.callStackSymbols;
    NSString *avoidCrashHandle = nil;
    if (type == AvoidCrashHandleType_doNothing) {
        avoidCrashHandle = @"忽略处理";
    }
    else if (type == AvoidCrashHandleType_returnNil) {
        avoidCrashHandle = @"返回nil";
    }
    else if (type == AvoidCrashHandleType_returnNSNotFound) {
        avoidCrashHandle = @"返回NSNotFound";
    }
    
    NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
    [userInfo setValue:reason forKey:@"reason"];
    [userInfo setValue:callStackSymbols forKey:@"callStackSymbols"];
    [userInfo setValue:avoidCrashHandle forKey:@"avoidCrashHandle"];

    dispatch_async(dispatch_get_main_queue(), ^{
        [[NSNotificationCenter defaultCenter] postNotificationName:CAIAvoidCrashNotification object:nil userInfo:userInfo];
    });
}


@end
